<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>商品添加</title>


<link rel="stylesheet"
	href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
<script
	src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script
	src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<script type="text/javascript" src="/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
	$(function() {

		$("#valiprice").blur(function() {

			var price = $(this).val();
			if (price < 0) {

				$("#price").html("价格不能为负").css("color", "red");
			}
		});
		
		$("#valiprice").change(function(){
			
			$("#price").html("");
		});
		$("#valiquantity").blur(function() {

			var quantity = $(this).val();
			if (quantity < 0) {

				$("#quantity").html("数量不能为负").css("color", "red");
			}
		});
		$("#nameinput").blur(
				function() {

					var value = $(this).val();
					var param1 = {
						"zybgoodname" : value
					};
					param = JSON.stringify(param1);
					//alert(param);
					$.ajax({
						type : "post",
						url : "/goods/valiname",
						dataType : "json",
						data : param,
						contentType : "application/json",
						success : function(data) {

							//alert(data.zybgoodname);
							if (data == null) {

								if (value.length == 0) {
									$("#valiname").html("请输入您要添加的商品名称").css(
											"color", "red");
								} else {
									$("#valiname").html("可以添加该商品").css("color",
											"green");
								}
							} else {
								$("#valiname").html("该商品已存在").css("color",
										"red");
							}
						}
					});
				});
	});
	
	
	
	
	function clo(){
		//然后刷新父类页面
		//window.opener.document.location.reload();
		window.close();
	}
</script>
</head>
<body>
	<div class="container">
		<ul class="breadcrumb">
			<li><a href="#">在线购物系统</a></li>
			<li><a href="#">商品管理</a></li>
			<li class="active">商品添加</li>
		</ul>
		<form:form action="/goods/addgood" modelAttribute="goods"
			method="post" class="form-horizontal" role="form">
			<div class="form-group">
				<label for="lastname" class="col-sm-2 control-label">商品名称</label>
				<div class="col-sm-10">
					<input type="text" class="form-control" name="zybgoodname"
						id="nameinput">
					<div id="valiname"></div>
				</div>

			</div>

			<div class="form-group">
				<label for="lastname" class="col-sm-2 control-label">商品单价</label>
				<div class="col-sm-10">
					<input type="text" class="form-control" name="zybprice"
						id="valiprice">
					<form:errors path="zybprice" cssStyle="color:red"></form:errors>
					<div id="price"></div>
				</div>
			</div>

			<div class="form-group">
				<label for="lastname" class="col-sm-2 control-label">商品数量</label>
				<div class="col-sm-10">
					<input type="text" class="form-control" name="zybquantity"
						id="valiquantity">
					<form:errors path="zybquantity" cssStyle="color:red"></form:errors>
					<div id="quantity"></div>
				</div>
			</div>
			<div class="form-group">
				<label for="lastname" class="col-sm-2 control-label">商品简介</label>
				<div class="col-sm-10">
					<textarea maxlength="100" class="form-control" name="zybgooddesc"></textarea>
					<form:errors path="zybgooddesc" cssStyle="color:red"></form:errors>
				</div>
			</div>

			<div class="form-group">
				<div class="col-sm-offset-2 col-sm-10">
					<input type="submit" class="btn btn-primary" value="添加"> <a
						href="#" class="btn btn-danger" onclick="clo();">取消</a>
				</div>
			</div>
		</form:form>
	</div>

</body>
</html>